<style scoped>
  body {background: #fbfbfb;}
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }
  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }
  .rj-cell.note label{
    float: left;
  }
  .rj-cell.note span{
    width: 80%;
    display: inline-block;
  }
  .weui-cells {
    margin-top: 0;
  }
  .weui-cells_form {
    background: #fbfbfb;
  }
  .weui-cell {
    background: #fff;
  }
  .weui-cells__title {
    text-align: left;
  }
  .oitem {
    padding: 3px;
  }
  .hide {
    display: none;
  }
  #acts {
    font-size: 0;
  }
  #acts span {
    font-size: 14px;
  }
  .halfbtn {
    display: inline-block;
    width: 49%;
  }
  .weui-label {
    text-align: left;
  }
  .aitem p {
    text-align: left;
    font-size: 14px;
    padding: 5px 0;
  }
  .weui-cells_form {
    background: #fbfbfb;
  }
  .btn-padded {padding: 15px;}
</style>
<template>
  <div class="addsell">
    <div style="height: 50px; line-height: 50px; background: #f7f7f7; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      收货地址列表
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="../../assets/back.png" style="width: 20px" />
      </a>
    </div>
    <div class="weui-cells weui-cells_radio">
      <label class="weui-cell weui-check__label" v-for="(addr, index) in addres" :key="addr.guid" :for="addr.guid">
        <div class="weui-cell__bd aitem">
          <p>{{addr.contact}}，{{addr.contactno}}</p>
          <p>{{addr.province}}{{addr.city}}{{addr.district}}  {{addr.addres}}</p>
        </div>
        <div class="weui-cell__ft">
          <input type="radio" class="weui-check" name="radio" :value="index" :checked="index == 0 ? true : false" :id="addr.guid">
          <span class="weui-icon-checked"></span>
        </div>
      </label>
      <a href="javascript:void(0);" @click="addAddr" class="weui-cell weui-cell_link">
        <div class="weui-cell__bd">添加地址</div>
      </a>
    </div>
    <div class="btn-padded">
      <a href="javascript:;" class="weui-btn weui-btn_primary" @click="fixAddr">确定</a>
    </div>
  </div>
</template>

<script>
import OutStoreRoom from "./OutStoreRoom";

export default {
  name: 'CustomerAddr',
  data () {
    return {
      openid: localStorage.openid,//'oIuV2v77MaLCAQILhjI6h6oTWpHI',
      addres: [],
      customerguid: ''
    }
  },
  created() {
    window.addEventListener('setItem', ()=> {
      this.openid = localStorage.getItem('openid');
    })
  },
  mounted () {
    this.customerguid = this.$store.state.customer.guid;
    console.log('list customerguid:', this.customerguid)
    this.getAddress();
  },
  methods: {
    addAddr: function() {
      this.$router.push({name: 'AddAddress'})
    },
    getAddress: function() {
      let that = this;
      this.axios({
        method: 'get',
        responseType: 'json',
        url: '/sales/Addresrecord!findAddress.action?operatorid=' + this.customerguid
      }).then(response => {
        if (response.data.status == "true") {
          that.addres = response.data.result;
        } else if (response.data.status == "false") {
          this.toastError(response.data.result);
        } else {
          this.toastError('系统错误');
        }
      });
    },
    fixAddr: function () {
      if (this.addres.length == 0) {
        this.toastText('无可选地址，请添加新地址！');
        return;
      }
      let index = $("input[name='radio']:checked").val();
      let addr = this.addres[index];
      console.log('addr:', addr)
      let storeAddr = {
        province: addr.province,
        city: addr.city,
        district: addr.district,
        address: addr.addres,
        contact: addr.contact,
        contactno: addr.contactno
      };
      this.$store.commit('setArriAddr', storeAddr);
      console.log('fixAddr:', this.customerguid)
      this.$router.push({name: 'AddSellform'});
    }
  }
}
</script>
